# !/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time : 2023/4/21 21:50
# @Author : xyjiang1216
# @Email : jiangxuyan@nudt.edu.cn
# @File : open_planner.py
# @Version: OpenPlanner2.0
import importlib

from OpenPlanner.core.src.layer_1_construct_topo import TopoConstructionModule
from OpenPlanner.core.src.layer_2_construct_stream import StreamConstructionModule
from OpenPlanner.core.src.layer_3_verify_scenario import ScenarioVerificationModule
from OpenPlanner.core.src.layer_4_preprocess_input import InputProcessingModule
from OpenPlanner.core.src.layer_5_plan_traffic import TrafficPlanningModule
from OpenPlanner.core.src.layer_6_transform_solution import SolutionTransformingModule
from OpenPlanner.core.src.layer_7_verify_solution import SolutionVerifyingModule
from OpenPlanner.core.src.layer_8_evaluate_solution import SolutionEvaluatingModule
from OpenPlanner.core.src.op_class import OPClass


def open_planner(conf):
    """
    OpenPlanner规划器入口
    :param conf: 配置文件的路径
    :return: none
    """

    '''初始化OPStruct，初始化配置参数'''
    print('Phase 1: parsing config json')
    op_obj = OPClass(conf)

    '''拓扑构建层'''
    print('Phase 2: constructing topo')
    topo_construct_module = TopoConstructionModule(op_obj)
    topo_construct_module.construct_topo_json()
    topo_construct_module.custom_topo_hook()

    '''流量构建层'''
    print('Phase 3: constructing stream')
    stream_construct_module = StreamConstructionModule(op_obj)
    stream_construct_module.construct_stream_json()
    stream_construct_module.custom_stream_hook()

    '''场景验证层'''
    print('Phase 4: verifying scenarios')
    scenario_verify_module = ScenarioVerificationModule(op_obj)
    scenario_verify_module.verify_scenario()

    '''输入预处理层'''
    print('Phase 5: pre-processing algo input')
    input_processing_module = InputProcessingModule(op_obj)
    input_processing_module.init_input()
    input_processing_module.custom_input_hook()

    '''规划算法层'''
    print('Phase 6: planning traffic')
    traffic_planning_module = TrafficPlanningModule(op_obj)
    traffic_planning_module.solving()

    '''输出转换层'''
    print('Phase 7: transforming solution')
    solution_transforming_module = SolutionTransformingModule(op_obj)
    solution_transforming_module.transform_solution()
    solution_transforming_module.custom_transforming_hook()

    '''结果验证层'''
    print('Phase 8: verifying solution')
    solution_verifying_module = SolutionVerifyingModule(op_obj)
    solution_verifying_module.verify_solution()

    '''质量评估层'''
    print('Phase 9: evaluating solution')
    solution_evaluating_module = SolutionEvaluatingModule(op_obj)
    solution_evaluating_module.evaluate_solution()
    solution_evaluating_module.custom_evaluating_hook()
